********* TABLE 4 *********
clear all
set more off 
capture log close
 
* main path
global path "~/Dropbox/Paraguay/1_data/7_replication_dataverse"
capture cd "$path"	

*tables = analysis tables
global tables "$path/tables"

eststo clear


********** CROSS-SECTIONAL ANALYSIS **********
*load data
use "$path/data/repression_cross.dta", clear

* Eigenvalue regression - cross sectional
reghdfe log_violations lambda_z, noabsorb cluster(district)
summ log_violations if e(sample)==1 
estadd local meanDep = trim("`: display %12.3fc `r(mean)''")
estadd local dept_fe = "No"
estadd local years = "Cross-sect."
eststo eigen1

* Degree regression - cross sectional
reghdfe log_violations degree_z, noabsorb cluster(district)
summ log_violations if e(sample)==1 
estadd local meanDep = trim("`: display %12.3fc `r(mean)''")
estadd local dept_fe = "No"
estadd local years = "Cross-sect."
eststo degree1

* Betweenness regression - cross sectional
reghdfe log_violations betweenness_z, noabsorb cluster(district)
summ log_violations if e(sample)==1 
estadd local meanDep = trim("`: display %12.3fc `r(mean)''")
estadd local dept_fe = "No"
estadd local years = "Cross-sect."
eststo between1

********** PANEL ANALYSIS **********
*load data
use "$path/data/repression_panel.dta", clear

* Eigenvalue regressions - panel
foreach fe in noabsorb "absorb(i.depa#i.year)" {
    local i = 2
    if "`fe'" == "noabsorb" {
        local dept_fe = "No"
    }
    else {
        local dept_fe = "Yes"
        local i = 3
    }
    reghdfe log_violations lambda_z, `fe' cluster(district)
    summ log_violations if e(sample)==1 
    estadd local meanDep = trim("`: display %12.3fc `r(mean)''")
    estadd local dept_fe = "`dept_fe'"
    estadd local years = "35"
    eststo eigen`i'
}

* Degree regressions - panel
foreach fe in noabsorb "absorb(i.depa#i.year)" {
    local i = 2
    if "`fe'" == "noabsorb" {
        local dept_fe = "No"
    }
    else {
        local dept_fe = "Yes"
        local i = 3
    }
    reghdfe log_violations degree_z, `fe' cluster(district)
    summ log_violations if e(sample)==1 
    estadd local meanDep = trim("`: display %12.3fc `r(mean)''")
    estadd local dept_fe = "`dept_fe'"
    estadd local years = "35"
    eststo degree`i'
}

* Betweenness regressions - panel
foreach fe in noabsorb "absorb(i.depa#i.year)" {
    local i = 2
    if "`fe'" == "noabsorb" {
        local dept_fe = "No"
    }
    else {
        local dept_fe = "Yes"
        local i = 3
    }
    reghdfe log_violations betweenness_z, `fe' cluster(district)
    summ log_violations if e(sample)==1 
    estadd local meanDep = trim("`: display %12.3fc `r(mean)''")
    estadd local dept_fe = "`dept_fe'"
    estadd local years = "35"
    eststo between`i'
}

* Create table
esttab eigen* degree* between* using "$tables/table4.tex", replace ///
    style(tex) booktabs ///
    cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) ///
    keep(lambda_z degree_z betweenness_z) ///
    stats(meanDep N r2 dept_fe years, ///
          fmt(%9.3f %12.0fc %9.3f %9.0s %9.0s) ///
          labels("Outcome mean" "Observations" "\$R^2\$" "Department-Year FE" "No. Years")) ///
    varlabels(lambda_z "Eigenvalue" ///
              degree_z "Degree" ///
              betweenness_z "Betweenness") ///
    starlevels(* 0.1 ** 0.05 *** 0.01) ///
    label mlabels(none) collabels(none) ///
    prehead("\begin{tabular}{lccccccccc}\hline\hline" ///
           "&\multicolumn{9}{c}{Human Rights Violations (log)}\\[1ex]") ///
    posthead("\hline") ///
    prefoot("\hline") ///
    postfoot("\hline\end{tabular}")
